nearly working network code!