Move clustering logic to metadata.