use Peter's updates to simplify code

See pull request:
#44651 Reduce number of data-ensure loops and variables