'data' needs to be reset inside the 'flag' controlled loop or *undefined* behavior is likely when user sets 'flag' and loop repeats without resetting 'data' to beginning of block.