modified addWords method