Added documentation.
Formatting and cleanup.