Added handling of edge detection