Code cleanup. Adding more tests.
20 files changed