Adding unit tests, fixing a cache problem