Modified clustering algorithm to use arrays and mutable sets