Added possibility for the user to disable sorting,
and changed a bit the sorting function.

Change-Id: I36fa0245de2e07cd084642d5ffa6152e68884d9e