Improved freeing of allocated structures.

Improved some internal documentation.