modified calculate ranking