Optimize expectation class.

Optimizes the expectation implementation.

Note: I could not find a way to run the spec tests. @bignimbus you will need to confirm from your end.