Merge pull request #23 from sotty/master

Avoid thread and memory leaks