More elegant query build