Refactored into coffeescript