almost to working version using R data