Added error handling to text snippet