A little refactoring to make batch update more robust