begin working on R flag; needs separate function for R to work