Abstract queueing code and add an output buffer on the main thread; make error handling code cleaner and more robust, add new unit tests
performance tweak: always feed output when spooling input