refactor length extract variable to eliminate duplicate.