Fix logic for long matches