detecting end of shape