Refactoring min and cache