Improve QueryHandler session handling as suggested by IchBinJoe
API subject to change and should not be used externally.