algorithm fixes