Refactor network module

It is now something resembling to an object. Makes it easier to handle
multiple networks in the future.