Added method for closing sockets, and cleaning up handlers.