fixed the leader election not working

and a number of other small bugs