closing sockets properly