code commented and logic moved in private function