Fix bug with ranking algorithm