fixed a bug in heartbeat callback that would not break the loop because of scoping issues