some algorithm fixes