Improved sync function.