Added most all the code required for the min-max algorithm. Should be good to go, but haven't run it yet. Going to take a lot of testing to get this to work right.