Moved role permission check into function