Modify A::D::Query to use POE events rather than while(1)

**Which issues (if any) does this change solve? (please link them here)**
n/a

**Briefly describe your fix. Are there any important details we should know about?**

* Uses POE's events correctly to generate the "infinite loop" effect
* Some other small changes for efficiency

**Are you having any problems? Do you need our help with anything?**
n/a