Latest working code - basic leader election