Removed unnecessary cleanup code before exiting, which actually had a chance to deadlock the client. All good now!