Updated version for readability.

Simplified inline comments and split code into logical segments for
improved readability.