better algorithm for populating rows