consolidated error handling