Move clustering logic to metadata.

Close #1297.
Here `attrToProjector["x"]` is overridden, but reference to old one is used inside. Inlining that results infinite loop.