fix bugs in Array span() and segment() + add tests