Better chat server
Added clean-up and error handling