Permissions update

I think this works, untested. Please tell me if there are any bugs and I
will fix