port has to be closed and deleted in the same thread as it was created. changed the disconnect function