refactored and added networking