Well, i think this one can be in separated method with some good describing name. It is hard to understand what is calculating/sorting here.