improve error recovery
Merge pull request #2056 from WalterBright/improveError

improve error recovery