restructured server.js file