refactor the ranking code a little