Refactored working directory resolver.