perrin's legacy R code for reference