Thanks to Emanuel
Fixed error in ranking calculation