Working segmentation rules, fixes #1

Full implementation of segmentation rules. Working program.