Fix disconnect/end function