Added support for disconnecting and cleaning up from client and server