simple js refactoring