Fix mem leak -- issue #38

Set of changes to fix the mem leak seen in issue #38