WIP: Cleaning the script. Removing repeated code