Modified insert functionality to return the promise only after all data in an array have been inserted