Fixed socket handling when connection fails.
Better logging