improve error recovery
Merge pull request #1841 from WalterBright/error_recovery

improve error recovery