code refactoring and caching