Fixing the url creation and determining type based on port number