Refactored minmax.pl