better logging, properly handle disconnection