reorganized/simplified code. also fixed the issue when you win.