Fix memory leak, closes #190