adding safeguards for invalid returns