Now closes all sockects correctly;