Fixed bug in ranking logic