Fix some bugs in the stack-reducing code (#2571)