better to test this with typeof cardIndex !== 'undefined'