raise correct excpetion when not connected, cleanup