Added centralized error handling  functionality