little js refactoring