added randomized spsegment test .. and fixed bugs