Midway through rewriting now for sockets.