Fixed issue with resolving host name
Added error handling.