updated and refactored POST behaviour in server.js