Fixed memory leak

fixes #7
fixes #6