Moved role flatting logic to protected function. Flattening logic skips
visited branches.