Refactored code for counting the values of the cards in a given hand.