revised check_win function