Fix optimizations; all tests pass.