Fix sessions and improve URI template matcher.