Fix error algorithm