Minor javascript refactor