adding code for insert-replace