Refactor Card and CardPile functions