split up functions; converted js to coffeescript