fixes to algo