added documentation
applied minor refactorings