Fixing queries

Some queries would always be ran, even if they had no effect. This
prevents that happening to save queries.