optimize code, change .map getOrElse to .exists