change loop from (0 .. data'length - 1) to 'range to support any kind of ranges of given data string