Rewrote the minmax algorithm