Many refactoring and commenting changes.