Cleanup: refactored code for calculating source wordcount