[Matahari] [PATCH] Some refactoring and bug fixes for the network API.