Simplified logic in getCanonicalKey()