What is the chdir for? Isn't this the last thing in the process?