Better election logic

Will change PIDs into ints because this is much simpler
in some cases
Changed pids to integers. Also made heartbeats contain message states,

which ensures reliable delivery (finally)