Is there a missing "end" here? Did you even test the scripts after the changes?