Improved URL handling and other fixes

Fixed in new commit.