Refactors getPermissions a bit.