More js refactoring