Fixed memory problems and added comments.
Fixes for CCC