Implements proper cwd handling.