Refactor to coffeescript