Added synchronization (sic.) and ensured shutdown hook has the correct
instances of the client and server.