DRY: This function has two parts that do almost the same thing. Make it into a protected function.