Correction from previous pull request. Some new changes.

Typographical error correction.
FIX resource leak.
Remove global variable.