Added various comments and code improvements.