Extract list matching logic from main loop