made sync code more DRY