Adds the new memory management into the main functions.
Merge pull request #3 from dstar4138/master

Adds the new memory management into the main functions.