fixing conditional statements in the mquery funtion