Started refactoring and documenting.