fix removal of empty segments to support all cases