factored custom uri build and redirection out into functions