building up queries