Added few error messages, better socket handling