changed so only takes last n words of input