working on getNonemptySegment method