optimise detection of min/max