Refactor min and max calculation
Simplify conditions by using any?