translated to coffee, fixed some bugs