[refactoring] common code in a single private function