Refactored error return