Added tests for server.js

server.js is now cleaner and easier to understand.