refined relative path logic and slight refactoring