Added error handling for recv