get rid of shadowing variables

Mostly by renaming the shadowing variable.
If a shadowing variable was deleted,
the shadowed one can be used instead.
Merge pull request #2583 from cremno/get-rid-of-shadowing-variables

get rid of shadowing variables