Fix segmentation fault and cleanup
Merge pull request #100 from gabriele-v/master

Fix segmentation fault and cleanup