revised error handling