next job locking to stop processing errors
Refactoring for better performance