Various fixes.
Added some more tests and fixed some more.