Refactor and cleanup to only do the data gathering and reset auto increment when I think it is needed.

Should speed up overall execution time with little risk to being more unstable than it already was.