lots more error checking, subprocess.Popen rather than os.system, some cleanup, trying to better PEP8 format