Fixing bugs in sockets code