refactor length rank
major refactoring