implemented thresholded flattening for cluster hierarchy
implemented average density calculation