almost done refactoring and documenting