Mass insert or replace function