Cleaned up a lot of the URI handling to reuse code more