Refactored server.js