Refactored network receive, and added unit tests.