refactored completely to coffeescript