Improved internal error handling