Minor js refactoring