handle truncating to zero words

cherry-pick from qzg:master with modifications
to rebase changes.

Conflicts:
	index.js
	test.js