corrected hanging issue with max finding routine