There is maybe some better ways to do this, but this method has the benefit to be clear and DRY.

However, i'm listening to every solutions.