Move chdir to it's own function called last