Refactor variables to top scope
Merge pull request #606 from ppp0/issue-606

Fixing little code smells