Refactored code to separate js files