Moves conditional out of query