Cleaned up some of the URL comparisons
Hopefully fixes issue when creating UIManagedDocuments which caused a crash
More tidying up