Update after code review comments.
Improved error messages and added a test