implemented win condition, excluded code duplication