Some refactoring to pathname.py