(WIP)
Cleaned up the code.
Added documentation comments.

Change-Id: I9714920f013d665545798e359aee68b08e9cf689