removed a lot of formatting and refactored the JavaScript