refactor length