added getCentroid function