Bug fix for 'OR' appearing at end of all queries