Minor refactoring and code comments.

- Extract few variables.
- Add missing comments.