Final fixes

Mainly Memory leak fixes and a few extra comments in the core.