Bug fixes and reworking of networking code