Optimize rank, rank0, rank1