Memleak fixes

Fixes #17.