Bring declarations closer to where they're needed.
Merge pull request #377 from Dmitry-Me/bringDeclarationsCloserToWhereTheyreNeeded

Bring declarations closer to where they're needed.