Major changes to thread handling

Added a monitor thread to join client connection threads. Fixed a
problem with kevent handling where a closed connection would mess stuff
up. Changed imports and generally cleaned everything up.