refactor make_query