fixed caching, refactor