logic for sync