refactored code in batch controller.