Refactor guessing game and add tests.