Improve the error message and the tests