tmp: added debugging prints
bug fix! logic cleaning

fixed bug: not able to extend segment without splitting it first.
cleaned some if logic and reduced nested depth.
added many debug prints to help find bug above (can be deleted).