attempt to organise server.js code