code refactoring: smaller drier js