Refactoring.

Improved comments, renamed some variables.