Use vectorized and non-buggy local maxmin function