copy coffeescript implementation over