Moved conditions to query