Fix bug around removing middle module

If any module other than the last was removed the indexes were not
resequenced.