refactored some fat out of server.js