Fix NameError: global name 'ranked' is not defined.