some changes to sync function