Rearrange code; realize that heartbeat is not used in notebook