small js refactor