Refactored JavaScript back into .js file