refactoring coffeescript to make it more idiomatic