Fix a potential server crash bug in the card handling code