Added proper disconnect handling