private void clear() {
        if (zooKeeper != null) {
            if (leaderOffer != null && zooKeeper.getState().isAlive()) {
                try {
                    zooKeeper.delete(leaderOffer.getOffer(), -1);
                    LOG.debug("Removed leader candidate {}", leaderOffer);
                } catch (InterruptedException e) {
                    failed(e);
                } catch (KeeperException e) {
                    failed(e);
                }

                if (leaderElectionAware != null) {
                    leaderElectionAware.onClosed(leaderOffer);
                }
                leaderOffer = null;
            }

            try {
                zooKeeper.close();
            } catch (InterruptedException e) {
                failed(e);
            } finally {
                zooKeeper = null;
            }
        }
    }