Code cleanup. Adding more tests.
11 files changed