Fixes memory leak from #593
Merge pull request #594 from CraftVersum/memory-leak-fix

Fixes memory leak from #593