refactoring
Cache factory, class rearrangement and some tests