improve sync logic