Broke up socket logic for cleanliness