group conditions correctly so that 'limit' won't be set to -1 for the query fucntion