HDFS-5673: code review feedback, attempting to flatten out the logic by using more iterations.