better handling of sockets