fix the script to work properly