refactor max and min to use ternary