Full script working - final version