better syncing algorithm