Improved the error message. And added final classes and tests.