Implemented 2 iteration algorithm for segmentation. Much improved but needs performance boost.