Adds correct closing of sockets