Refactored Network. There are still bugs.