You've got this 'nth item or repeat the last item forever' pattern over and over. Pull it out and give it a name.