implement minimax, other cleanup