modified cluster.R