Refactor XHR query execution code. Closes #39.