Rewrote the script with modules