Added some more unit tests, also fixed a bug discovered when adding unit tests.

Change-Id: I424dd169228b89a75a19caa3c42027e3d8bf20e8