Fix sorting issue

TNL-952
i tried to follow guidelines and updated the code, is it ok now ?