Moved check guess logic into a function.