Improved error handling.
Numerous bug fixes.