Minor Cache fix, added tests, various cleanup