Big mess from network branch, but commited here because the network is kind of abandoned