Some refactoring and documenting.