fixed cache mode
more fixes
small refactoring