fix deadlock in heartbeat check
improve disconnecting mechanism
fix race condition in buffer access
improve debug message