Implementation of clean disconnecting & logging