fix the code that determines when to publish batch