Move ref.strip() into a try block