Put loadEventsIntoHeaders into DB edit function

Also fixed a bug with the nested loops