try to fix heartbeat_length
reformat code (it was a mess)