Fix some cwd-related bugs.