refactoring cards.c