tidy up QueryAPI and give it a success function