lots of URI-handling fixes