Refactored code to split into multiple .js files