refactored coffeescript for events