added some memory cleanup code and memory debugging code
Merge pull request #19 from 5-second-rule/memory-management

added some memory cleanup code and memory debugging code
merged with master