Added more cleanup to main()

Some memory wasn't being deleted/free'd.
Some Cleanup functions weren't being called.
Added new cleanup functions, and call them.