minor js refactoring