refactoring + caching