Refactor role checking for more comprehensive code.