Revised error handling