refactor some stuff into coffeescript, make some other changes