Tests and fix queryaddresses

I have added a few basic tests, as well as a few improvements.