Refactor reused code into private function