Added some comments here and there, and did some error checking when connection to the server.