Added more tests and fixed lots of buglets.