updated dynamic leader detection

* refactored partition handling