updated code, clearner and produces a dendogram of final output