Segmentation algorithm now works.
Fixed the bug with probability calcuation.