Bug fix to working directory handling