Fixed a memory leak
Added various comments