weighted centroid and bug fix for rendering

weighted centroid and bug fix for rendering