Reorder checks, move declaration closer to where it's needed
Merge pull request #427 from Dmitry-Me/reorderChecksMoveDeclaration

Reorder checks, move declaration closer to where it's needed