Ported source to coffeescript, minor cleanup