Improving the resiliency of sync

Removed rerere
Start extracting sync functionality into library