rewritten using coffeescript