Fixed error reporting and more unit tests.