fixed memleaks and etc.
Merge pull request #15 from intersvyaz/patch-3

fixed memleaks and etc.