Mark max and min values
Refactored min/max code