#21707 Made code more generic to avoid extra editing