added edge detection code