Refactored some of the javascript code to remove repeated lines, AND changed directory structure