code for hierarchical clustering