Formatted all documents.
Minor refactoring and commenting.