Refactored and documented code.