copied cards.c from HFC