Too much duplicated code in this anonymous function. Suggest using a private function instead.