Replace duplicated code with a existing helper function.