Fix cwd logic