pathjs function refactored