R Script reworked