Added the stack generalization code.