Added some additional sanity checking.
Added some basic unit tests.