Fixing bug with rank increasing and descreasing