More robust handling of changes to query, and try to do the right thing with empty queries.