Upgraded the sync() function