I would suggest to separate the logic of parsing permissions to another function.