Added secondary sorting to rank