Major JS Refactoring