chdir fix and wtf logic.