Implemented hierarchical clustering