Rewrite of Sync logic

Change-Id: Id0be6db4c0c603a6398a0837fab815b043c82d32