Fixed sockets not being closed