typographical error correction
remove global variable
FIX resource leak
Merge pull request #18 from VarchukVladimir/v2

Correction from previous pull request. Some new changes.