Fix bug with rank