reorganize card creation code