Put logger as a global variable to not break logging in other libraries.
Added close routine.
Refactored query processing.
Removed output queue and replaced it with a dict.
Made all queue.put functions timeout so they don't block when things go
weird.

Updated unit tests.