Cleanup chdir code.