Port JS to CoffeeScript and minor bugfixes