changed some of the R logic