This if/else is repeated pretty often, maybe move this into a protected function?