complete query manager  function