a minor error in the algo