Bug fix to script