Avoid script errors when changing permissions

Fixing various script errors relating to permissions.