Small js refactoring