Bring variable declarations closer to where they're first used.
Merge pull request #382 from Dmitry-Me/bringDeclarationsCloserToWhereTheyAreNeeded

Bring variable declarations closer to where they're first used.