added documentation to refactored code