Card filtering and code cleanup