Refactored membership permission code