The code is duplicated, a base function should be created, and the function to use should be given as a callback to this base function.