Safe url handling

We should consider merging this.