Update code so that this can be called many times