Refactor write() and heartbeat() to use new verifyConnection() method