Minor JavaScript refactor