Merged both scripts into one