Fixed edge detection to work all of the time and put in 4 levels