refactor ag-replace