This function looks a lot like the first one. We should extract a helper function instead of repeating ourselves.