Optimised way of finding max and min