Modified r script