Refactor cards.c