Added exception handling to heartbeat connection