small refactor to the getWidthFromLength stuff to make it self-contained and more concise. Now appends to docElem as well, fixes #177