Fix some issues with the sync code