Adds documentation.
Adds documentation and cleans up internal functions.