minor bugfix, close socket before instantiating a new one.