Small commit -- see datails.

Moved the query switch to the relative controllers but logout.
Made some fixes and trying to improving the performance.