Ported changes from masterkale into coffeescript