simplifying some variable checking and how the queries are handled;