Added part of the sorting function