Correct replacement logic