Support for thread-safe message printing, pruning of closed connections, and listening for incoming messages added.  Comments added for locations of new functions.