Pass by ref
Cache output from getTopLevelIdentifier (reduces cost by about 30%)