refactor to clean up server.js