Query building. Implementing make-query