some refactoring and documenting