Cache tree passing all tests. Tests neeed refactoring.

Code cleanup probably overdue.