Refacored some network stuff