I've seen this same block of code before in this patch can we just use the same function not duplicate it?