updating both scripts to have better control flow