refactoring worker.js (similar to work done in app.js to simplify code and fix whatever is breaking the server.