improve cwd handling