minor javascript refactor