Removed unnecessary cleanup code before exiting, which actually had a chance to deadlock the client. All good now!
Merge pull request #229 from fragmer/master

Fixed a couple shutdown issues.