added unit test for networking, fixed up networking code (needs a refactor)