refactoring, adding caching