Improved error output message.  Refs #7789.
Fixed bugs in code and unit test. Refs #7789.