Make relative reference replacement more efficient