Still working out bug in edge detection algorithm