Updated to check return value of chdir()