Adds query count ability to allow for nested queries.  As it was, running a nested query would automatically reopen (and therefore close in a replicated nvironment) the database of the calling query.