Fixed stalemate problem, added new debug code.