Port javascript to coffeescript. Fix some deprecated _to_function stuff.