replaced dispose() with close() when disconnecting