"""
    clusterdata = organizeclusters(smd::SMD)

Organize pre-clusters into a vector indexing distinct clusters.

# Description
Pre-clusters in the input `smd`, as related by their shared integer value k_off
`smd.connectID`, are organized into a vector of matrices `clusterdata`.  Each
index of `clusterdata` corresponds to a distinct cluster.
"""
function organizeclusters(smd::SMD)
    # Isolate and sort some arrays from the smd structure.
    connectID = smd.connectID
    sortindices = sortperm(connectID)
    combineddata = [smd.x smd.y smd.x_se smd.y_se smd.framenum smd.datasetnum smd.connectID]
    combineddata = combineddata[sortindices, :]

    # Loop over preclusters and organize member localizations into a more 
    # accessible format.
    npercluster = counts(connectID)
    npercluster = npercluster[npercluster .!= 0]
    ncumulative = [0; cumsum(npercluster)]
    uniqueIDs = unique(connectID)
    nclusters = length(uniqueIDs)
    clusterdata = Vector{Matrix{Float32}}(undef, nclusters)
    for nn = 1:nclusters
        clusterind = (1:npercluster[nn]) .+ ncumulative[nn]
        clusterdata[nn] = [combineddata[clusterind, :] sortindices[clusterind]]
    end

    return clusterdata
end

"""
    clusterdata = organizeclusters(smd)

Organize pre-clusters into a vector indexing distinct clusters.

# Description
Pre-clusters in the input `smd`, as related by their shared integer value k_off
`smd.connectID`, are organized into a vector of matrices `clusterdata`.  Each
index of `clusterdata` corresponds to a distinct cluster.
"""
function organizeclusters(smd)
    # Isolate and sort some arrays from the smd structure.
    connectID = smd.connectID
    sortindices = sortperm(connectID)
    combineddata = [smd.x smd.y smd.x_se smd.y_se smd.framenum smd.datasetnum smd.connectID]
    combineddata = combineddata[sortindices, :]

    # Loop over preclusters and organize member localizations into a more 
    # accessible format.
    npercluster = counts(connectID)
    npercluster = npercluster[npercluster .!= 0]
    ncumulative = [0; cumsum(npercluster)]
    uniqueIDs = unique(connectID)
    nclusters = length(uniqueIDs)
    clusterdata = Vector{Matrix{Float32}}(undef, nclusters)
    for nn = 1:nclusters
        clusterind = (1:npercluster[nn]) .+ ncumulative[nn]
        clusterdata[nn] = [combineddata[clusterind, :] sortindices[clusterind]]
    end

    return clusterdata
end