Added various comments for better understanding, see document block as well as inline comments.