Added check permission before changing permissions.