Refactor: put updateCardCounts into a separate function