Move declarations closer to where they're first used
Merge pull request #411 from Dmitry-Me/moveDeclarationsCloserToWhereTheyreNeeded

Move declarations closer to where they're first used