Better socket handling