More bug fixes.
Added more tests.