Fixed formatting and refactored js code into its own file.