code from the first submission to CRAN