Refactored the scope name algorithms.