Minor restructurings for performance in the optimizer as well as some tracing support.