added more efficent code with the os.chdir statements