Major rework of the script