Added sort support.
Improved error tolerance.