Fix scope of some variables

as reported by Cppcheck
Merge pull request #39 from tbeu/fix-scope

Fix scope of some variables