replaced sort algorythm, fixed equals sort values