Code cleanup, more tests.