Add more unit tests.

Fixed some bugs found with the unit tests.