Add function to handle network