improve defReplace fn