optimize table insert and remove calls