minor JavaScript refactor