Improved URL handling and other fixes

That's embarrassing :) I'll fix it.