Adding checks to query filter