Lots of improvements and cleanup; output stream may now also be sent via
UDP.