fix error in the rank function