Extracted function to retrieve single element or fail