Bug 25444: Simplify the code using a loop