Fix rank bug