Fixing error-correction routine