functional sort and save rankings