Updated final script- not tested yet