Move replacement into a separate function

So we can add other functions to handle more specific cases.