Removed unnecessary refs
Improved disconnect logic and added some light comments
Removed old definition of client state