Adding detail unit tests and cleaning up some of the related source.
Add a sanity check