small js refactoring