moved heartbeat code