refactored minimax - got rid of duplication within the function