Fix memory leaks.
Remove unnecessery friend class.