made it to check for max and min at the same time
bug correction