added try catch to chdir()