Better handing of invalid input.

On error, output msg to stderr and exit with a non-zero status code.
Added a test suite framework; added tests.