improved R scripts