Fixed “multiple times in the output” bug.  Identified other bugs in win detection logic.