Working segmentation rules

Full implementation of segmentation rules. Working program.