Refactoring javascript file 5/24