updated select.R code