refactoring coffeescript functions