added better restart behaviour for closing ports