That looks more elegant than my solution here.
Just as a reference, there’s a third topic with the same question here.