Better cleanup and improved readability.

If query_engine fails to start, it doesn't cleanup properly.
Somehow, this hasn't bitten us yet. Fixed now.
Methods checking for nil is not a common code pattern.
To prevent confusion, I've moved the nil checks one level up,
which is what people usually do.
Merge branch 'rowcache'