Fixed resource leaks
Merge pull request #7 from Zhro/zhro/resourceleaks

Fixed resource leaks