Extra fixes to try to get the optimization to behave nicely.