Added networking code from Casper Hornstrup