Fixed the minimax function