Modularized the edge detection code