added proper sorting for ranks