Look at Spin Sort and Normalization, and also Embedding.