cleaned up and added explanation to R scripts