lots of updates to ag loading script

Mucho buenoer. Cleaned up the whole script, added sanity checks, re-wrote cleanup code.