refactored function for toggle card display