refactoring max and min function using tournament function