Refactored min and max methods