Added some convenience bits of code and modified the UnitTest accordingly.
Fixed a few bugs and improved unit test.