Modified insert code to run in intervals