implemented win function