Added some code to calculate clusters