Fixing rank calculation