Merge network and instance code, misc improvements