Refactored js into one file to work on the server