Bring variables decalaration to where they are really needed.
Merge pull request #361 from Dmitry-Me/reduceVariablesLifetime

Bring variables declaration to where they are really needed.