Add more tests and fix error reporting