Added tons more tests. Fixes for bugs found by tests.