repaired sync logic