Fixed problem with closing sockets by changing the test .. not optimal