Format, small amount refactoring and documentation.