Modernize code (and avoid variable shadowing)
(cherry picked from commit da6ca21e1c25b0ee3453a9250b545fbcbf1ac4b5)