slight js refactor