fix error -> wrong end of edge detection