enhanced error handling