fixed typo
worked on algorithm for handle segment overflow