Improved error reporting. Fixed some failing tests.