avoid mutating port value

creates a new string to use as needed, instead of mutating
see also #286, #290