minimax + refactor