Refactored the JS to follow coding standards and work more efficiently.