refactoring batch message handling