Added debug logic for edge detection