Your solution certainly removes the duplicated code but I don't think it's worth it. First it's a little slower because it runs through the subcomponents twice and second it's more difficult to understand what the code actually does. I still like the copy-paste way better.