fixed algorithm error