fully updated to remove use of sockets