added conditions to make this run and insert on any 3 tables