some cleanup and moved `words` creation out of to on end function