Complete rewrite in CoffeeScript