Refactored code base to simplify server.js.