Separate winning logic from main api interface. Added JUnit tests