fixing local port issue and crash on client close