Closing socket properly
Implemented a method for closing currently connected socket, and a method for checking is socket is still connected.
Removing comments and minor refactoring