added checks for invalid queries.