#21707 Made code more generic