rewrote most of the network code, for new api