Refactored the .js files to a better structure