Improve heartbeat script, make it pythonic and such