Working on memory management

Release is almost complete, just fixing memory leaks.