networking improvements and code cleanup