redid the whole thing in R.