Fixes for leader election and more cleanup