Refactor URL path helper and add tests

Improves path helper implementation and moves it into a private method. Adds tests.