Fix undefined variables

close #201
Fix unexpected global var
Merge pull request #1 from Lokaltog/master

Sync to master