Finally found bug in logic and now working; now for min() and max()