Trying to add memoization to minmax to see if it helps. Terrible code.