More work on network layer - rewriting it (it was a bit overengineered).