Stacking algorithm fixes.