I think the pattern can be even simpler. Can you show some sample inputs and what you want to see as outputs?