Refactor the server and javascript webapp