add code to handle closed curve.