Added some needed memory management.