little fixes and optimizations

i was getting weird errors when running the script on a bunch of files
so i just changed things as necessary. Again, run_analysis is wrong.