Fixed some bugs in card management