Moved code to QueryQueue class