updating the script to handle truncating elements with no child elements