Optimized the synchronization code so that it is much faster now.