Added function comments. Moved doSearch as a private function and some code clean up