designing and implementing the sync logic