Improve closing of the sync