grabbed code from mcts.ai