Updated R script with code for more parts