Some bugfixes to network code