Memory and Comment cleanup

Cleaned up memory management and comments.
Also added extra unit test.