It's better to use local variable to find max and min. And at the end of function compare it with global max and min