Added documentation and fixed the order of end-point drawing.