I think all of this can be replaced by window.location.origin