Added more tests. Fixed a few problems found.