ported version from adobe-zookeeper with many modifications