Fixed bug in stage2 in optimizing expressions.