Fixing tests. Code cleanup.