rearrange code
add a coffeescript version of sync.js