fixed rank calculation error