refactored and documented code