changed to output when matched, not at end