refactored the network layer and added unit tests