Refactor card code