Unit test development

also a few small code improvements. More granular error message.