Factored out buildPageUrl code - has bugs need to fix