refactoring index by private function.