quick refactor of contour detection