added socket error handling