refactoring javascript architechture