MODIFIED: cleaned up query task