added method for drawing and refactored centroid calculation code