socket handling improved