A lot of leader election bug fixes