Can't this just be a for loop? Might be simpler.