Refactorated the sortWords method before adding threads