made similarity graph more efficient. Including old clustering code