Improved documentation.
Added several comments to make the code more readable.