Fixed an issue that prevented workers to be respawned when the status code was different from 0
Broke the code into a more testable form