majority of code translated to coffeescript