Fix the script logic